﻿namespace CSharpPro._1023;

public class Test
{
    public static void BubbleSort(int[] array)
    {
        if (array == null || array.Length <= 1)
            return;

        int n = array.Length;
        bool swapped; 
        
        for (int i = 0; i < n - 1; i++)
        {
            swapped = false;
            
            for (int j = 0; j < n - 1 - i; j++)
            {
                if (array[j] > array[j + 1])
                {
                    int temp = array[j]; 
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                    swapped = true;
                }
            }
            
            if (!swapped)
                break;
        }
    }
    
    public static void PrintArray(int[] array)
    {
        foreach (int num in array)
        {
            Console.Write(num + " ");
        }
        Console.WriteLine();
    }

}